﻿
@{
    Layout = null;
}
<style>
    .tdpatTitle {
        margin: 0 0 0 38px;
        padding-top: 52px;
        font-size: 25px;
        color: #00a0ea;
    }
</style>
<script src="@SiteUrl.GetStaticResourceScriptUrl("~/js/validate/jquery.validate.min.js")"></script>
<link href="~/Content/css/card.css" rel="stylesheet" />
<form id="formapply">
    <div class="row">
        <div id="dv_opdetail" role="tabpanel" class="tab-panel col-sm-12">
            <div class="col-sm-4 wrapper" id="dv_opdetailpat">
                <table class="form">
                    <tr>
                        <td class="formTitle tdpatTitle" rowspan="3" style="font-weight:bold;"><span id="sq_xm">姓名</span></td>
                    </tr>
                    <tr></tr>
                    <tr></tr>
                    <tr>
                        <th class="formTitle"></th>
                        <td colspan="3" style="font-weight:bold;">
                            (住院号：<span id="sp_sq_zyh" style="font-weight:bold;color:#00a0ea;width:100px;">___________</span>)
                            <input id="sq_zyh" value="" type="hidden" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">基本信息：</th>
                        <td class="formValue" colspan="3"><span id="sq_basic">___________</span></td>
                    </tr>
                    <tr>
                        <th class="formTitle">病区：</th>
                        <td class="formValue" colspan="3"><span id="sq_bqmc">___________</span></td>
                    </tr>
                    <tr>
                        <th class="formTitle">床号：</th>
                        <td class="formValue" colspan="3"><span id="sq_bedcode">___________</span></td>
                    </tr>
                    <tr>
                        <th class="formTitle">入院诊断：</th>
                        <td class="formValue" colspan="3"><span id="sq_ryzdmc">___________</span></td>
                    </tr>
                </table>
            </div>
            <div class="product-info col-sm-8" style="height:430px;padding-right:5px;">
                <div class="panel-heading">
                    <span style="width:50px;"></span>
                </div>
                <table class="form">
                    <tr>
                        <td class="formValue" colspan="3">
                            <span id="Applyno" style="color:#00a0ea;font-weight:bold;"></span>
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>拟手术名称：</th>
                        @*<td class="formValue formDdlSelectorTd" colspan="2">
                                <input id="ssdm" type="hidden" />
                                <input id="ssmcn" attr-ssdm="" attr-zjm="" name="ssmcn" type="text" class="form-control required" autocomplete="off" />
                            </td>*@

                        <td class="formValue" colspan="4">
                            <table id="tablessmc">
                                <tr>
                                    <td>
                                        <i id="zdCircle" class="fa fa-plus-circle plusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i>
                                    </td>

                                    <td class="formValue">
                                        <input type="text" class="form-control activeValue focusInput ssmcText" id="ssmc" name="ssmc" />
                                        <input id="ssdm" type="hidden" />
                                    </td>
                                </tr>
                            </table>
                        </td>

                    </tr>
                    <tr>
                        <th class="formTitle "><span class="required">*</span>手术时间：</th>
                        <td class="formValue" colspan="3">
                            <input id="sssj" type="text" class="form-control input-wdatepicker formClearIgnore required" style="width:70%;" value="" onfocus="WdatePicker({ dateFmt: 'yyyy-MM-dd' })" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">手术部位：</th>
                        <td class="formValue formDdlSelectorTd" colspan="2">
                            <input id="ssbw" type="text" class="form-control" />
                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">麻醉方式：</th>
                        <td class="formValue formDdlSelectorTd" colspan="2">
                            <select id="AnesCode" name="AnesCode" class="form-control" style="width:95%;float:left;">
                                <option value="">===请选择=== </option>
                                <option value="1"> 全身麻醉 </option>
                                <option value="2">局部麻醉</option>
                                <option value="3">针刺麻醉</option>
                                <option value="4">复合麻醉</option>
                            </select>

                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>主刀医生：</th>
                        <td class="formValue formDdlSelectorTd " colspan="2">
                            @*<select id="ysgh" name="ysgh" class="form-control " style="width:95%;float:left;">
                                    <option value="">===请选择=== </option>
                                    <option value="1">医生A </option>
                                    <option value="2">医生B</option>
                                    <option value="3">医生C</option>
                                    <option value="4">医生D</option>
                                </select>*@
                            <input id="code1" type="hidden" />
                            <input id="ysgh" attr-code="" attr-zjm="" name="ysgh" type="text" class="form-control required" autocomplete="off" />

                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle">麻醉医师：</th>
                        <td class="formValue formDdlSelectorTd " colspan="2">
                            <input id="code2" type="hidden" />
                            <input id="mzys" attr-code="" attr-zjm="" name="mzys" type="text" class="form-control" autocomplete="off" />

                        </td>
                    </tr>
                    <tr>
                        <th class="formTitle"><span class="required">*</span>是否隔离：</th>
                        <td class="formValue formDdlSelectorTd">
                            <select id="isgl" name="isgl" class="form-control required" style="width:95%;float:left;" data-enumtype="EnumIsgl"></select>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <div style="padding-top:50px;padding-right:50px;" id="dv_apply_btn">
                                <a class='btn btn-default' style='width:100px;background:#00CD66;color:#eee;height:20px;font-size:13px;padding-top:5px;float:right;' onclick="submitApply();">提交申请</a>
                            </div>
                            @*<input type="button" id="btn_search" class="btn btn-primary" onclick="" value="提交申请" style="float:right;padding:5px 10px 5px 10px"/>*@
                        </td>
                    </tr>
                    <tr>
                        <td colspan="4">
                            <div style="padding-top:10px;padding-right:50px;display:none;" id="dv_cancel_btn">
                                <a class='btn btn-default' style='width:100px;background:#ff6a00;color:#eee;height:20px;font-size:13px;padding-top:5px;float:right;' onclick="submitCancel();">取消申请</a>
                            </div>
                            @*<input type="button" id="btn_search" class="btn btn-primary" onclick="" value="提交申请" style="float:right;padding:5px 10px 5px 10px"/>*@
                        </td>
                    </tr>
                    <tr></tr>
                    <tr></tr>
                </table>
            </div>
        </div>

    </div>
</form>
<script>
    //var keyValue = $("#Applyno").val();
    $(function () {
    

        $("#ssdm").bindSelect({
            url: "/Operation/Common/GetOplist",
            id: "ssdm",
            text: "ssmc",
            minimumResultsForSearch: 0
        });
        //$("#ysgh").bindSelect({
        //    url: "/Operation/Common/GetStafflist",
        //    id: "rygh",
        //    text: "ryxm",
        //    minimumResultsForSearch: 0
        //});
        $("#AnesCode").bindSelect({
            url: "/Operation/Common/GetAneslist",
            id: "AnesCode",
            text: "AnesName",
            minimumResultsForSearch: 0
        });
        //手术名称
  //      $("#ssmcn").ssmcFloatingSelector({
  //          organizeId:'',
  //          width: 400,
  //          itemdbclickhandler: function ($this) {
  //              $("#ssmcn").val($this.attr('data-ssmc')).attr("attr-ssdm", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
  //              var ssmc = $("#ssdm").val($this.attr('data-ssmc')).val();
  //              var ssdm = $("#ssdm").val($this.attr('data-ssdm')).val();
  //              $("#ssmcn").html(ssmc);
  //              $("#ssdm").html(ssdm);
  //          }
		//});
		$("#ysgh").staffFloatingSelector({
			organizeId: '',
			width: 200,
			itemdbclickhandler: function ($this) {
				$("#ysgh").val($this.attr('data-name')).attr("attr-code", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
				var name = $("#code1").val($this.attr('data-name')).val();
				var code = $("#code1").val($this.attr('data-code')).val();
				$("#ysgh").html(name);
				$("#code1").html(code);
			}
		});
		$("#mzys").staffFloatingSelector({
			organizeId: '',
			width: 200,
			itemdbclickhandler: function ($this) {
				$("#mzys").val($this.attr('data-name')).attr("attr-code", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
		        var name = $("#code2").val($this.attr('data-name')).val();
		        var code = $("#code2").val($this.attr('data-code')).val();
				$("#mzys").html(name);
		        $("#code2").html(code);
	        }
        });
    });

	//手术名称 新增icon
	$('#tablessmc .plusToggleCircle').click(function () {
		var number = $('#tablessmc .ssmcText').length + 1;
		//var $newTr = $('<tr><th class="formTitle">副7</th><td class="formValue"><input type="checkbox" id="chk' + number + '" class="chkValue" style="float:left;" /><label style="float:left;margin-top:3px;">疑似</label><input type="text" id="zd' + number + '" class="form-control activeValue focusInput zdText" style="width:70%;" /><i class="fa fa-times" aria-hidden="true" hidden></i></td><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td></tr>');
		var $newTr = $('<tr><td><i class="fa fa-minus minusToggleCircle" aria-hidden="true" style="margin-left: 10px; color: #6ff3ad; font-size: large;"></i></td><td class="formValue"><input type="text"  id="ssmc' + number + '" name="ssmc' + number + '" class="form-control activeValue focusInput ssmcText" /><input id="ssdm' + number + '" type="hidden" /></td></tr>');
		$newTr.appendTo($(this).closest('table'));
		//手术名称浮层
		bindssmcFloatingSelector(number);
	});

	//删除icon
	$('#formapply').on('click', '.minusToggleCircle', function () {
		$(this).closest('tr').remove();
	});

	//主手术浮层
	bindssmcFloatingSelector(0);

	//手术名称浮层
	function bindssmcFloatingSelector(num) {
		var number = num;
		if (num != 0) {
			number = number - 1;
		}
		var defaults2 = {
			url: '/SystemManage/SysBaseData/GetOperationList',
			width: 400,
			height: 200,
			clickautotrigger: true,
			caption: "选择诊断",
			ajaxparameters: function($thisinput) {
				//return "organizeId=" + options.organizeId + "&keyword=" + $thisinput.val();

				return "keyword=" + $thisinput.val() + "&type=true";
			},
			itemdbclickhandler: function ($this) {
				if (num == 0) {
					$("#ssmc" ).val($this.attr('data-ssmc')).attr("attr-ssdm", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
					var ssmc = $("#ssmc" ).val($this.attr('data-ssmc')).val();
					var ssdm = $("#ssdm").val($this.attr('data-ssdm')).val();
					$("#ssmc" ).html(ssmc);
					$("#ssdm" ).html(ssdm);
				} else {
					$("#ssmc" + num).val($this.attr('data-ssmc')).attr("attr-ssdm", $this.attr('data-id')).attr("attr-zjm", $this.attr('data-zjm'));
					var ssmc = $("#ssmc" + num).val($this.attr('data-ssmc')).val();
					var ssdm = $("#ssdm" + num).val($this.attr('data-ssdm')).val();
					$("#ssmc" + num).html(ssmc);
					$("#ssdm" + num).html(ssdm);
				}
			},
			colModel: [
				{ label: '代码', name: 'id', hidden: true },
				{ label: '手术名称', name: 'ssmc', widthratio: 60 },
				{ label: '助记码', name: 'zjm', widthratio: 20 },
				{ label: '手术代码', name: 'ssdm', widthratio: 20 }
			]
		};
		var options2 = $.extend(defaults2, options2);

		if (num == 0) {
			$('#ssmc').newtouchFloatingSelector(options2);
		} else {
			$('#ssmc' + num + '').newtouchFloatingSelector(options2);
		}
	}


    function submitApply() {

        //console.info("姓名：" + $("#sq_xm").text());
        //console.info("住院号：" + $("#sq_zyh").val());
        var xingbie = $("#sq_basic").text();
        var arr = xingbie.split(",");
        //console.info("性别：" + arr[0]);
        //console.info("年龄：" + arr[1]);
        //console.info("病区：" + $("#sq_bqmc").text());
        //console.info("床号：" + $("#sq_bedcode").text());
        //console.info("入院诊断：" + $("#sq_ryzdmc").text());

        var datajbxx = "{\"xm\":\"" + $("#sq_xm").text() + "\",\"zyhs\":\"" + $("#sq_zyh").text() + "\",\"xb\":\"" + arr[0] + "\",\"nl\":\"" + arr[1] + "\",\"bq\":\"" + $("#sq_bqmc").text() + "\",\"ch\":\"" + $("#sq_bedcode").text() + "\",\"ryzd\":\"" + $("#sq_ryzdmc").text() +"\"}";

		//debugger
		var keyValue = $("#Applyno").val();
		if (!$('#formapply').formValid()) {
			return false;
		}
		var thetime = $("#sssj").val();
		var d = new Date(Date.parse(thetime.replace(/-/g, "/")));

		var curDate = new Date();
		//if (d <= curDate) {
		//	window.$.modalAlert("手术申请时间不得早于当天", 'warning');
		//	return false;
		//}

		//var ssmc = $("#ssdm option:selected").text();
		//$("#ssmcn").val(ssmc);
		var postData = $("#formapply").formSerialize();
        var ssmcn = $("#ssmc").val();
		postData.ssmcn = ssmcn;
		postData.ysgh = $("#code1").val();
		postData.ysxm = $("#ysgh").val();
        postData.mzys = $("#code2").val();

		//手术名称列表
		var ssList = [];
		ssList.push({ ssmc: $("#ssmc").val(), ssdm: $("#ssdm").val() });
		var i = 2;
		while ($("#ssdm"+i).val() != undefined) {
			//ssObj.ssmc = $("#ssmc"+i).val();
			//ssObj.ssdm = $("#ssdm"+i).val();
			//ssList.push(ssObj);
			ssList.push({ ssmc: $("#ssmc"+i).val(), ssdm: $("#ssdm"+i).val() });
			i++;
		}
		postData.ss = ssList;
        $.submitForm({
            url: "/Operation/OpApply/SubmitForm?datas=" + datajbxx+"&keyValue=" + keyValue,
            param: postData,
            success: function (data) {
                //debugger
                $("#Applyno").html("手术申请编号：" + data.data.applyno);

                $("#gridListOP").resetSelection();
                $("#gridListOP").trigger("reloadGrid");

                $('#myTab [href="#linkpat"').trigger('click');
            }
        });
    }

    //撤销手术申请详情
    function submitCancel() {
        var keyValue = $("#Applyno").val();
        $.deleteForm({
            url: "/Operation/OpApply/DeleteApply",
            param: { keyValue: keyValue },
            success: function () {
                $("#gridListOP").resetSelection();
                $("#gridListOP").trigger("reloadGrid");

                $('#myTab [href="#linkpat"').trigger('click');
            }
        });
    }


</script>